<template>
	<view>
		<view class="c" v-for="(item,index) in datalist">
			<view class="">
				{{item.legal_name}}
			</view>
			<view class="bts" @click="savebind(item.id)">
				确认绑定
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				group_id:'',
				device_no:'',
				datalist:[]
			}
		},
		onLoad(options) {
			console.log(options)
			this.device_no = options.device_no
			this.getdata()
		},
		methods: {
			getdata(){
				var that = this
				uni.showLoading({
					title: '加载中...'
				})
				uni.request({
					url: this.global.url + 'api/allocation/get_sub',
					method: 'POST',
					header:{'token':uni.getStorageSync('token')},
					data: {
						// clinic_id: uni.getStorageSync('token')
					},
					success(res) {
						let result = res.data
						console.log(result)
						if (result.code == 1) {
							// 存用户信息
							that.datalist = result.data
							
						} else {
							uni.showToast({
								title: result.msg,
								icon: 'none'
							})
						}
					},
					complete() {
						uni.hideLoading()
					}
				})
			},
			savebind(id){
				var that = this
				uni.showLoading({
					title: '加载中...'
				})
				uni.request({
					url: this.global.url + 'api/allocation/binduser',
					method: 'POST',
					header:{'token':uni.getStorageSync('token')},
					data: {
						user_id:id,
						device_num:that.device_no
						// clinic_id: uni.getStorageSync('token')
					},
					success(res) {
						let result = res.data
						console.log(result)
						if (result.code == 1) {
							// 存用户信息
							uni.showToast({
								title: result.msg,
								icon: 'none'
							})
							setTimeout(()=>{
								uni.navigateBack()
							},1000)
						} else {
							uni.showToast({
								title: result.msg,
								icon: 'none'
							})
						}
					},
					complete() {
						uni.hideLoading()
					}
				})
			}
		}
	}
</script>

<style>
.c{
	display: flex;
	justify-content: space-between;
	align-items: center;
	width: 80%;
	margin: 0px auto;
	margin-top: 30rpx;
	margin-bottom: 30rpx;
	
}
.bts{
	padding: 15rpx;
	border-radius: 10rpx;
	border: 1px solid #0000ff;
	color: #0000ff;
	font-size: 20rpx;
}
</style>
